package com.cloud.yadang.user.controller;


import com.cloud.yadang.user.api.BusService;
import com.cloud.yadang.user.commons.R;
import com.cloud.yadang.user.entity.User;
import com.cloud.yadang.user.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2023-02-10
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LitemallUserController {

    private final UserService userService;

    private final BusService busService;

    /**
     * 查询所有用户信息
     *
     * @return R
     */
    @GetMapping("/list")
    public R<List<User>> list() {
        return R.ok(userService.list());
    }

    @GlobalTransactional
    @GetMapping("/listNOPermisssion")
    public R<List<User>> listNOPermisssion() {
        User user = new User();
        user.setUsername("kkk");
        userService.save(user);
        String bus = busService.bus();
        System.out.println("BUS服务调用结果："+bus);
        int i = 1/0;
        return R.ok(userService.list());
    }

    /**
     * 根据id获取用户
     *
     * @param id 用户id
     * @return R
     */
    @GetMapping("/getById")
    public R<User> getById(String id) {
        return R.ok(userService.getById(id));
    }
}
